Intel vulkan driver introduction

0x1 Overview

As we know, mesa has supported vulkan driver for four different platforms, these four platforms are Intel,AMD,Qualcomm Adreno,Broadcom V3D. Currently vulkan driver support in mesa is not using Gallium architecture like OpenGL,its architecture seems child stage, the four vulkan drivers don’t have much shared common codes, the abstraction of the four vulkan drivers is the architecture optimization of mesa vulkan driver in the next stage.It has widely discussed in the mesa dev community.And the coming optimized architecture will accelerate the supporting for more GPU platforms like Mali GPU and Imagination GPU.

In this article, I will show you how Intel Vulkan driver is supported in mesa.

Let’s have a look of Intel GEN GPU hardware architecture.

The following diagram is about the hardware block of the Intel GEN GPU


Here is the 3D pipeline block of Intel Gen GPU. the left part is the 3D pipleine, the right part is the GPU hardware block.


The GPU driver (userspace and kernel space) will configure the above hardware block according to graphics API’s input, then trigger gpu hardware to execute as its configuration. So GPU driver’s task is simple, just to configure the GPU hardware!

0x2 Component overview

We know mesa includes several abstraction layers. it supports different graphics api,different compiler frontend, different gpu hardware code generation.

In mesa, Intel vulkan driver’s module name is ANV.Here is the diagram about how ANV driver is built from different sub component.

And here is the relationship of intel vulkan driver library and its dpendencies.

0x3 Mem interface

GPU harware needs serveral input data for further processing, like vertex buffer, texture buffer, uniform buffer and surface, these buffer will be accessed by CPU and GPU together. so mesa should provide interface to alloc/release buffer, set these buffer’s address to GPU hardware then issue hardware to execute it.

Let’s have brief explanation about how buffer alloc/release happen in ANV vulkan driver.

Here is the sequence about allocating gem buffer.

Here is the sequence about releasing buffer.

Here is the sequence about issuing command to kernel driver.

For performance optimization, ANV can use a cache mechansim to boost the performance since the memory alloc/release is resource heavy operation. In broadcom close source v3d driver, it uses a similar mechansim like linux slab to cache buffer in userland driver.

0x4 Typical objects in vulkan

Here are several important objects of vulkan concepts. RenderPass object and ShaderModule object are passed to Pipeline through VkGraphicsPipelineCreateInfo when creating Pipeline object. then Pipeline is binded to CommandBuffer using VkCmdBindPipeline api, after that the commanbuffer can use the passing Pipeline object, RenderPass object and ShaderModule object.

0x5 GPU codegen

Here is the diagram about generating gpu code from SPIRV code.

The gpu code is the code which will run on Intel GPU’s EUs(execution unit), it is programmable shader unit, likes broadcom v3d’s QPU.

The input of the pipeline is SPIRV code, the SPIRV format is the standard IR for different shader formats like glsl,opencl.

Then ANV driver will convert it to mesa internal IR format(NIR) code.

Then it will be optimized by different passes, this idea is similar as other compiler’s optimization passes.

The last step is gpu code generation.It uses typical graphic coloring algorithm. at this stage,we must read the GPU programmer guide carefully,then learn how to generate effective code for intel gen gpu.

0x6 Framebuffer dump

This feature is useful for us to check the render result in the framebuffer. it is similar as we can use glReadPixels to read back framebuffer’s content on OpenGL.

Currently mesa’s anv dump code has bug to blit framebuffer to write image, and I have fixed it to make this feature can work well.

Here is the diagram about how to dump framebuffer.

It uses gdb call method to dump data, here is the use instruction about it.

  • To dump the framebuffers of an application after each render pass, all you
  • have to do is the following
    *
  • 1) Start the application in GDB
  • 2) Run until you get to the point where the rendering errors occur
  • 3) Pause in GDB and set a breakpoint in anv_QueuePresentKHR
  • 4) Continue until it reaches anv_QueuePresentKHR
  • 5) Call anv_dump_start(queue->device, ANV_DUMP_FRAMEBUFFERS_BIT)
  • 6) Continue until the next anv_QueuePresentKHR call
  • 7) Call anv_dump_finish() to complete the dump and write files

Here is the dump result with the above method.

0x7 Hardware state dump

It uses preload method to hook api, the hook api will dump state to a file.

Here is the diagram about it.

Here is the gdb command for capturing data

gdb -iex “set exec-wrapper env LD_PRELOAD=/home/kevin/mesa/mesa_build_vulkan/libexec/libintel_dump_gpu.so INTEL_DUMP_GPU_CONFIG=/home/kevin/mesa/test_intel_dump_gpu/dump_config” –args “/home/kevin/vulkan/build/bin/multithreading”

Then we can use Aubinator Viewer to check the dumped states. please notice that this dump mechansim is also working for Opengl case, and the dump items are the same as Vulkan’s since the dump is for getting content of gpu hardware statue.

The dump item shows what vulkan driver program the hardware. we can see the following states’s content like 3DSTATE_VS and other states.